package com.hnust.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hnust.entity.Alarm;
import com.hnust.entity.dto.AlarmDto;
import com.hnust.service.AlarmService;
import com.hnust.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 创建人：zhangRuWang
 * 创建时间：2022/5/6
 * 描述：
 */
@RestController
@RequestMapping("/alarm")
@Slf4j
@CrossOrigin("*")
public class AlarmController {
    @Autowired
    private AlarmService alarmService;

    @GetMapping("/search")
    public R<Page<AlarmDto>> alarmSearch(
            int page,int pageSize,String beginTime,String endTime
    ){
        log.info("搜索预警信息：{},{},{},{}",page,pageSize,beginTime,endTime);
        Page<AlarmDto> alarmDtoPage=alarmService.alarmSearch(page,pageSize,beginTime,endTime);
        return R.success(alarmDtoPage);
    }

    @PostMapping("/deal")
    public R<String> alarmDeal(@RequestBody AlarmDto alarmDto){
        log.info("修改预警信息：{}",alarmDto);
        Alarm alarm=new Alarm();
        alarm.setId(alarmDto.getId());
        alarm.setDealWith(alarmDto.getDealWith());
        alarmService.updateById(alarm);
        return R.success("修改成功");
    }

}
